package com.example.hanchen.yongkanggy.http;


import com.example.hanchen.yongkanggy.entity.StatusCode;
import com.example.hanchen.yongkanggy.entity.verificationimgEntity;
import com.example.hanchen.yongkanggy.utils.PreferencesUtil;
import com.example.hanchen.yongkanggy.utils.SharePreferencesConsts;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.File;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


public class UserRepository {

    private ApiService apiService;


    public UserRepository() {
        Gson gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
                .create();//使用 gson coverter，统一日期请求格式

        /*接口域名地址*/
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://ykga.java.68hanchen.com/")
                .client(new OkHttpClient.Builder().addInterceptor(new HeaderInterceptor()).build())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();

        apiService = retrofit.create(ApiService.class);
    }


    public Observable<StatusCode> clientuserlogin(String account, String password,String code, String parameterSign) {
        return apiService.clientuserlogin(account, password,code, parameterSign)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }


    public Observable<verificationimgEntity> verificationimg(File file, String moduleName) {
        return apiService.verificationimg(file, moduleName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
}
